<template>
  <div>
    <a-spin :spinning="confirmLoading" style="background: #fff">
      <j-form-container :disabled="false">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-collapse v-model="activeKey">
            <a-collapse-panel key="1" header="基本信息">
              <a-row :gutter="48">
                <a-col :span="8" :hidden="true" >
                  <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle">
                    <a-input
                      v-model="model.bpmBizTitle"
                      placeholder="请输入标题"
                      :max-length="255"
                      disabled
                    ></a-input>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billNo">
                    <a-input
                      v-model="model.billNo"
                      placeholder="请输入单据编号"
                      disabled
                    ></a-input>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="填表时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
                    <j-date
                      placeholder="请选择填表时间"
                      v-model="model.createTime"
                      :show-time="true"
                      date-format="YYYY-MM-DD HH:mm:ss"
                      style="width: 100%"
                      disabled
                    />
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="经办人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
                    <select-user-by-dep
                      :multi="false"
                      v-model="model.proposer"
                      disabled></select-user-by-dep>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="经办部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerDeptId">
                    <j-select-depart :disabled="formDisabled" v-model="model.proposerDeptId" disabled/>
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-collapse-panel>
            <a-collapse-panel key="2" header="汇款信息">
              <a-row
                :gutter="48"
              >
                <a-col :span="24" style="margin-top:45px">
                </a-col>
                <a-col :span="8">
                  <a-form-model-item
                    label="汇款单位名称"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    prop="remittanceUnit"
                  >
                    <select-customer-input commercialType="1" :disabled="formDisabled" v-model="model.remittanceUnit" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="汇款日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remittanceDate">
                    <j-date
                      placeholder="请选择汇款日期"
                      v-model="model.remittanceDate"
                      style="width: 100%;"
                      disabled
                    />
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item
                    label="汇款金额（元）"
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    prop="remittanceAmount"
                  >
                    <a-input-number
                      :max="99999999"
                      :min="0"
                      v-model="model.remittanceAmount"
                      placeholder="请输入汇款金额"
                      style="width: 100%"
                      disabled
                    />
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="支付方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payMode">
                    <j-dict-select-tag
                      type="list"
                      v-model="model.payMode"
                      dictCode="collect_money_mode"
                      placeholder="请选择支付方式"
                      disabled
                    />
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="收款单位名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payeeUnit">
                    <select-Company-input :disabled="formDisabled" v-model="model.payeeUnit" placeholder="请选择收款单位" @back="selectUnit" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8" v-if="model.payMode == '1'">
                  <a-form-model-item label="收款银行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankName">
                    <!--迭代11 增加一个收款银行，放到收款账户字段前面，该两个字段改为带出可编辑。-->
                    <a-input :disabled="formDisabled" v-model="model.bankName" placeholder="请输入收款银行" disabled></a-input>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8" v-if="model.payMode == '1'">
                  <a-form-model-item label="收款账户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payeeAccountNo">
                    <a-input :disabled="formDisabled" :max-length="32" v-model="model.payeeAccountNo" placeholder="请输入收款账户" disabled></a-input>
                    <!-- <select-company-bank-input  :disabled="formDisabled" v-model="model.payeeAccountNo" :companyId="model.payeeUnit"/> -->
                    <!-- <select-company-files-input :disabled="formDisabled" v-model="model.payeeAccountNo" /> -->
                  </a-form-model-item>
                </a-col>

                <a-col :span="24">
                  <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
                    <a-textarea
                      v-model="model.remark"
                      rows="4"
                      placeholder="请输入备注"
                      :max-length="500"
                      disabled />
                  </a-form-model-item>
                </a-col>
                <a-col :span="24" style="margin-bottom:45px">
                </a-col>
              </a-row>
            </a-collapse-panel>
            <a-collapse-panel key="3" header="认领信息">
              <a-row :gutter="48">
                <a-col :span="8">
                  <a-form-model-item label="认领人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employeeId">
                    <select-user-by-dep
                      :multi="false"
                      v-model="model.employeeId"
                      disabled></select-user-by-dep>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="是否为保证金" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDeposit">
                    <j-dict-select-tag
                      disabled
                      type="list"
                      v-model="model.isDeposit"
                      dictCode="is_deposit"
                      placeholder="请选择是否为保证金"
                      @input="radioIsDeposit"
                    />
                  </a-form-model-item>
                </a-col>
                <template v-if="model.isDeposit=='1'">
                  <a-col :span="8">
                    <a-form-model-item
                      label="关联保证金申请单"
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      prop="depositBillId"
                    >
                      <select-finance-deposit-bill-input isReturn="0" :feeCategory="'1,2'" :applicant="model.payeeUnit" :disabled="formDisabled" v-model="model.depositBillId" @back="getdepositBill"/>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="8">
                    <a-form-model-item
                      label="保证金类型"
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      prop="feeCategory"
                    >
                      <j-dict-select-tag
                        type="list"
                        v-model="model.feeCategory"
                        dictCode="fee_category_project"
                        placeholder="请选择保证金类型"
                        disabled
                      />
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="8">
                    <a-form-model-item
                      label="保证金金额（元）"
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      prop="depositRemittanceAmount"
                    >
                      <a-input
                        v-model="model.depositRemittanceAmount"
                        placeholder="请输入保证金金额"
                        disabled
                      ></a-input>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="8">
                    <a-form-model-item
                      label="利息金额（元）"
                      :labelCol="labelCol"
                      :wrapperCol="wrapperCol"
                      prop="interestAmount"
                    >
                      <a-input-number
                        :disabled="formDisabled"
                        v-model="model.interestAmount"
                        placeholder="请输入利息金额"
                        style="width: 100%"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                </template>
                <template v-if="model.isDeposit=='0'">
                  <a-col :span="16">
                    <div style="margin-bottom: 6px;margin-top: 6px">
                      <a-button @click="handleAdd" v-if="!formDisabled" type="primary">新增</a-button>
                    </div>
                  </a-col>
                  <a-col :span="4">

                  </a-col>
                  <a-col :span="4">
                    <div style="margin-bottom: 6px;margin-top: 6px;float:right">
                      单位：元
                    </div>
                  </a-col>
                  <a-col :span="24">
                    <a-table
                      ref="table"
                      size="middle"
                      rowKey="id"
                      bordered
                      :loading="loading"
                      :columns="columns"
                      :components="draggableComponent"
                      :pagination="false"
                      :data-source="model.itemList"
                      :scroll="{x:scrollX}"
                    >
                      <span slot="projectId" slot-scope="text, record">
                        <a @click="goProjectDetail(record)">{{ loadProjectId(text) }}</a>
                      </span>
                      <span slot="action" slot-scope="text, record">
                        <template v-if="!formDisabled">
                          <a-button
                            class="ruleButton"
                            :ghost="true"
                            type="primary"
                            icon="edit"
                            @click="handleEdit(record)"/>
                          <a-divider type="vertical"/>
                          <a-popconfirm title="确定复制行吗?" @confirm="() => handleCopy(record)">
                            <a-button
                              class="ruleButton"
                              :ghost="true"
                              type="primary"
                              icon="copy"
                            />
                          </a-popconfirm>
                          <a-divider type="vertical"/>
                          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                            <a-button
                              class="ruleButton"
                              :ghost="true"
                              type="primary"
                              icon="delete"
                            />
                          </a-popconfirm>
                        </template>
                      </span>
                    </a-table>
                  </a-col>
                </template>
                <!-- <a-col :span="24">
                  <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
                    <a-textarea :disabled="formDisabled" v-model="model.remark" rows="4" placeholder="请输入备注" :max-length="500" />
                  </a-form-model-item>
                </a-col> -->
                <!-- <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
                  <a-button @click="submitForm">保 存</a-button>
                </a-col> -->
              </a-row>
            </a-collapse-panel>
            <a-collapse-panel key="4" header="附件信息">
              <a-row :gutter="48">
                <a-col :span="24">
                  <a-form-model-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachments">
                    <j-upload :disabled="formDisabled" v-model="model.attachments"></j-upload>
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-collapse-panel>
          </a-collapse>
        </a-form-model>
        <common-flow-list v-if="formBpm && model.bpmStatus !== '1'" :formData="formData" style="margin-top: 10px"></common-flow-list>
        <erp-finance-collect-money-item-modal ref="itemList" :payeeUnit="model.payeeUnit" @ok="modalFormOk" ></erp-finance-collect-money-item-modal>
        <!-- 项目详情开始 -->
        <erp-project-report-modal ref="projectReport"></erp-project-report-modal>
        <!-- 项目详情结束 -->
      </j-form-container>
      <a-row :gutter="48">
        <a-col :span="24" style="text-align: center;margin-top: 15px">
          <a-button type="primary" v-if="formBpm" :style="{ marginRight: showFlowSubmitButton?'10px':'0px' }" @click="onPrint">打印</a-button>
          <a-button @click="submitForm('submit')" v-if="showFlowSubmitButton">保 存</a-button>
        </a-col>
      </a-row>
      <ErpFinanceCollectMoneyApplicationBillForm_editPrint v-if="formBpm && isSubmit" id="financeContent1" class="print_style" :formData="model1" :formDataHistory="formData"></ErpFinanceCollectMoneyApplicationBillForm_editPrint>
    </a-spin>
  </div>
</template>

<script>
  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import moment from 'moment'
  import { mapGetters } from 'vuex'
  import Decimal from 'decimal.js'
  import SelectPersonInput from '@/views/scy/components/SelectPersonInput'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
  import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
  import SelectFinanceDepositBillInput from '@/views/scy/components/SelectFinanceDepositBillInput'
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
  import ErpFinanceCollectMoneyItemModal from './ErpFinanceCollectMoneyItemModal'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import CommonFlowList from '@/views/components/CommonFlowList.vue';
  import ErpFinanceCollectMoneyApplicationBillForm_editPrint from './ErpFinanceCollectMoneyApplicationBillForm_editPrint'
  import { DragResizable } from '@/mixins/DragResizable'
  import Print from '@/utils/print/printarea.js';
export default {
  name: 'ErpFinanceCollectMoneyApplicationBillForm',
  components: {
    SelectUserByDep,
    SelectPersonInput,
    SelectTeamInput,
    SelectCustomerInput,
    SelectProjectInput,
    SelectFinanceDepositBillInput,
    ErpFinanceCollectMoneyItemModal,
    SelectCompanyInput,
    CommonFlowList,
    ErpFinanceCollectMoneyApplicationBillForm_editPrint,
    ErpProjectReportModal: () => import('@/views/erp/report/project/modules/ErpProjectReportModal')
  },
  props: {
    // 流程表单data
    formData: {
      type: Object,
      default: () => {},
      required: false
    },
    // 表单模式：true流程表单 false普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  mixins: [DragResizable],
  watch: {
    activeKey(key) {
      this.$forceUpdate()
    }
  },
  data() {
    return {
      isSubmit: true,
      model: {
        itemList: []
      },
      model1: { // 打印数据
        itemList: []
      },
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      activeKey: ['1', '2', '3', '4'],
      confirmLoading: false,
      validatorRules: {
        bpmBizTitle: [
              { required: true, message: '请输入流程标题!' }
          ],
         remittanceUnit: [
            { required: true, message: '请选择汇款单位!' }
        ],
        remittanceDate: [
            { required: true, message: '请选择汇款时间!' }
        ],
        remittanceAmount: [
            { required: true, pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入汇款金额!' }
        ],
        payeeUnit: [
            { required: true, message: '请选择收款单位!' }
        ],
        payeeAccountNo: [
            { required: true, message: '请选择收款账户!' }
        ],
        isDeposit: [
            { required: true, message: '请选择是否是保证金!' }
        ],
        depositBillId: [
            { required: true, message: '请选择保证金申请单!' }
        ],
        interestAmount: [
            { required: true, pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入利息金额!' }
        ],
        payMode: [
            { required: true, message: '请选择支付方式!', trigger: 'blur' }
        ],
        bankName: [
          { required: true, message: '请选择收款银行!' }
        ]
      },
      url: {
        queryProjectReportById: '/api/erp/project/report/erpProjectReport/queryById',
        getBillNo: '/api/erp/finance/collectMoney/erpFinanceCollectMoneyApplicationBill/getBillNo',
        add: '/api/erp/finance/collectMoney/erpFinanceCollectMoneyApplicationBill/add',
        edit: '/api/erp/finance/collectMoney/erpFinanceCollectMoneyApplicationBill/edit',
        queryById: '/api/erp/finance/collectMoney/erpFinanceCollectMoneyApplicationBill/queryById'
      },
      loading: false,
      dictOptions: {},
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectId',
          width: 100,
          ellipsis: true,
          scopedSlots: { customRender: 'projectId' }
        },
        {
          title: '项目编号',
          align: 'center',
          dataIndex: 'projectCode',
          width: 100,
          ellipsis: true
        },
        {
          title: '项目承接人',
          align: 'center',
          dataIndex: 'projectUndertaker',
          width: 100,
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['projectUndertaker'], text + '')
            }
          }
        },
        {
          title: '业绩归属年度',
          align: 'center',
          dataIndex: 'projectYear',
          width: 100,
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['projectYear'], text + '')
            }
          }
        },
        // {
        //   title:'费用所属年度',
        //   align:"center",
        //   dataIndex: 'teamYear',
        //   customRender: (text,r) => {
        //     if (!text) {
        //       return ''
        //     } else {
        //       return filterMultiDictText(this.dictOptions['teamYear'], text + '')
        //     }
        //   }
        // },
        {
          title: '经营团队',
          align: 'center',
          dataIndex: 'busiTeamId',
          width: 100,
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['busiTeamId'], text + '')
            }
          }
        },
        {
          title: '项目合同',
          align: 'center',
          dataIndex: 'contractNo',
          width: 100,
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['contractNo'], text + '')
            }
          }
        },
        // {
        //   title:'项目进度',
        //   align:"center",
        //   dataIndex: 'projectPlan',
        //   customRender: (text) => {
        //     if (!text) {
        //       return ''
        //     } else {
        //       return filterMultiDictText(this.dictOptions['projectPlan'], text + '')
        //     }
        //   }
        // },
        {
          title: '合同款项',
          align: 'center',
          dataIndex: 'contractMoneyItemId',
          width: 100,
          customRender: (text) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['contractMoneyItemId'], text + '')
            }
          }
        },
        {
          title: '应收款（元）',
          align: 'center',
          width: 100,
          dataIndex: 'receivables'
        },
        {
          title: '已收款（元）',
          align: 'center',
          width: 100,
          dataIndex: 'collectedMoney'
        },
        {
          title: '累计扣款（元）',
          align: 'center',
          width: 100,
          dataIndex: 'totalDeductMoney'
        },
        {
          title: '本次收款（元）',
          align: 'center',
          width: 100,
          dataIndex: 'amount'
        },
        {
          title: '本次扣款（元）',
          align: 'center',
          width: 100,
          dataIndex: 'deductMoney'
        },
        {
          title: '未回款（元）',
          align: 'center',
          width: 100,
          dataIndex: 'unreturnedMoney'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          // fixed: 'right',
          width: 147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          }
        }
      ],
      isChecked: false
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    }
  },
  created() {
    // 备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
    // 如果是流程中表单，则需要加载流程表单data
    this.showFlowData()
    // 加载数据字典信息
    this.initDictConfig();
    this.customKey = 'columns'
    this.columnswidth = this[this.customKey].map(val => {
      return val.width
    })
  },
  methods: {
    loadProjectId(text) {
      if (!text) {
        return ''
      } else {
        return filterMultiDictText(this.dictOptions['projectId'], text + '')
      }
    },
    goProjectDetail(record) {
      const that = this
      this.$nextTick(() => {
        getAction(this.url.queryProjectReportById, { id: record.projectId }).then((res) => {
          if (res.success) {
            const model = res.result
            that.$refs.projectReport.getDetail(model);
            that.$refs.projectReport.title = '项目一览表';
          }
        })
      })
    },
    selectUnit(data) {
      if (data) {
        this.$set(this.model, 'payeeAccountNo', data[0].bankAccountNo)
      }
    },
    // 选择是否是保证金
    radioIsDeposit() {
      this.$set(this.model, 'depositBillId', null);
      this.$set(this.model, 'depositRemittanceAmount', '');
      this.$set(this.model, 'feeCategory', null);
      this.$set(this.model, 'itemList', []);
    },
    // 获取保证金申请单信息
    getdepositBill(data) {
      if (data) {
        this.$set(this.model, 'depositRemittanceAmount', data[0].remittanceAmount);
        this.$set(this.model, 'feeCategory', data[0].feeCategory);
      }
    },
    // 关联单号
      relBillData(data) {
        if (!this.model.depositBillId) {
          return false
        }
        let id = this.model.depositBillId;
        if (this.model.isDeposit == '1') { // 项目保证金申请单
          getAction('/api/erp/finance/deposit/erpFinanceProjectDepositBill/queryById', { 'id': id }).then((res) => {
            if (res.success) {
                let data = res.result;
                this.$set(this.model, 'depositRemittanceAmount', data.remittanceAmount);
                this.$set(this.model, 'feeCategory', data.feeCategory);
                // this.model1 = this.model
            }
          })
        }
      },
    // 获取编号
    getBillNo() {
      let that = this;
      getAction(this.url.getBillNo, {}).then((res) => {
        if (res.success) {
          let data = res.result.records || res.result
          this.$set(this.model, 'billNo', data);
        }
      })
    },
    // 加载数据字典信息
      async initDictConfig() {
        initDictOptions('erp_omc_team_manager,alias_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'busiTeamId', res.result)
          }
        })
        initDictOptions('tdnd_type').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'teamYear', res.result)
          }
        })
        initDictOptions('yjgsnd').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectYear', res.result)
          }
        })
        initDictOptions('erp_omc_project,project_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectId', res.result)
          }
        })
        initDictOptions('erp_omc_contract_manager_final,htmc,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'contractNo', res.result)
          }
        })
        initDictOptions('erp_employee_file,name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectUndertaker', res.result)
          }
        })
        // 合同款项
        initDictOptions('erp_progress_payment_node,node_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'contractMoneyItemId', res.result)
          }
        })
        // 项目进度
        initDictOptions('erp_progress_contract_node,node_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectPlan', res.result)
          }
        })
      },
      // 子表新增
    handleAdd() {
      this.$refs.itemList.add();
      this.$refs.itemList.title = '新增';
      this.$refs.itemList.disableSubmit = false;
    },
    // 子表编辑
    handleEdit(record) {
      this.$refs.itemList.edit(record);
      this.$refs.itemList.title = '修改';
      this.$refs.itemList.disableSubmit = false;
    },
    // 子表复制行
    handleCopy(record) {
      let model = Object.assign({}, record);
      model.id = parseInt(Math.random() * 1000000000000);
      this.model.itemList.push(JSON.parse(JSON.stringify(model)))
    },
    // 子表删除
    handleDelete(id) {
      for (let i = 0; i < this.model.itemList.length; i++) {
        if (this.model.itemList[i].id == id) {
          this.model.itemList.splice(i, 1);
        }
      }
    },
    modalFormOk(data) {
      this.loading = true;
      let flag = true;
      // debugger;
      for (let i = 0; i < this.model.itemList.length; i++) {
        if (this.model.itemList[i].id == data.id) {
          this.model.itemList.splice(i, 1, data);
          flag = false;
        }
      }
      if (flag) {
        this.model.itemList.push(data);
      }
      this.loading = false;
    },
    ...mapGetters(['userInfo']),
    add() {
      this.edit(this.modelDefault);
      this.getBillNo();
      this.model.proposer = this.userInfo().empId;
      this.model.proposerDeptId = this.userInfo().deptId;
      this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
    },
    edit(record) {
      this.$refs.form.resetFields()
      this.model = Object.assign({}, record)

      this.model.employeeId = this.userInfo().empId;
      this.model1 = Object.assign({}, record)
      this.model1.employeeId = this.userInfo().empId;
      if (record.isDeposit == '1') {
        this.relBillData();
      }
      this.isChecked = this.model.itemList&&this.model.itemList.length==1
      this.visible = true
      this[this.customKey].forEach((val,index) => {
        val.width = this[this.customKey+'width'][index]
      })
    },
    // 渲染流程表单数据
    showFlowData() {
      if (this.formBpm === true) {
        let params = { id: this.formData.dataId }
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result)
          }
        })
      }
    },
    handleEmpty(data) {
      console.log(data);
    },
    submitForm() {
      this.isSubmit = false
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let itemList = this.model.itemList || [];
          // 保证金为否时，需要添加子表数据
          if (this.model.isDeposit == '0') {
            if (itemList == null || itemList.length == 0) {
              that.$message.warning('请填写认领信息表格！')
              that.confirmLoading = false
              return;
            }
          }
          if(this.isChecked){
            // 判断收款款项有一个没有填写数据时
            var itemLength= itemList.filter(value => !value.contractMoneyItemId).length
            if (itemList.length>0 && itemLength > 0) {
              that.$message.warning('请完善认领信息中的数据！')
              that.confirmLoading = false
              return;
            }
          }

          // 判断收款款项是否存在多条，多条判断款项是否相同
          if (itemList != null && itemList.length > 1) {
            for (var i = 0; i < itemList.length - 1; i++) {
              for (var j = i + 1; j < itemList.length; j++) {
                if (itemList[i].contractMoneyItemId === itemList[j].contractMoneyItemId) {
                  that.$message.warning('请确保认领信息中不存在相同的合同款项！')
                  that.confirmLoading = false
                  return;
                }
              }
            }
          }
          if (itemList != null && itemList.length > 0) {
            let amount = new Decimal(0);
            itemList.forEach(element => {
              amount = amount.add(element.amount)
            });
            amount = amount.toNumber().toFixed(2)
            if (this.model.remittanceAmount != amount) {
              that.$message.warning('汇款金额不等于收款金额总和！')
              that.confirmLoading = false
              return;
            }
          }
          httpAction(httpurl, this.model, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
                // 重新获取数据

                let params = { id: this.formData.dataId }
                getAction(this.url.queryById, params).then((res) => {
                  if (res.success) {
                    // this.edit(res.result)
                    this.isSubmit = true
                    this.model1 = res.result
                  }
                })
              } else {
                that.$message.warning(res.message)
                that.$emit('unButtonDisable');
              }
            }).catch(() => {
              that.$emit('unButtonDisable');
            })
            .finally(() => {
              that.confirmLoading = false
            })
        } else {
          that.$emit('unButtonDisable');
        }
      })
    },

    // 点击打印
    onPrint () {
        let print = new Print({
          el: '#financeContent1',
          popTitle: '收款申请详情 · 禾美环保',
          endCallback() {

          }
        })
      }
  }
}
</script>
<style>
  @import "../../../../../utils/print.css";
</style>
